package letcode.oneQuestionPerDay._202003._20200318;

/*
矩阵重叠优化
 */
public class _20200318_RectangleOverlap_1 {
    public static void main(String[] args) {
        int[] rec1 = {-521, -586, -487, 992};
        int[] rec2 = {-557, 114, -180, 267};
        System.out.println(isRectangleOverlap(rec1, rec2));
    }

    //提供方法
    public static boolean isRectangleOverlap(int[] rec1, int[] rec2) {
/*        //逆向思维，考虑什么时候不重叠就行
        if (rec2[2] <= rec1[0] || rec2[0] >= rec1[2]|| rec2[1] >= rec1[3]|| rec2[3] <= rec1[1])
            return false;
        else
            return true;*/
        return !(rec2[2] <= rec1[0] || rec2[0] >= rec1[2]|| rec2[1] >= rec1[3]|| rec2[3] <= rec1[1]);
    }
}

